// 用户功能请求模块
import request from '../utils/request'
import store from '../store'

// 登录请求
export function login(data) {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}

/* 发送验证码 */
export function sendSms(mobile) {
  return request({
    method: 'GET',
    url: `/v1_0/sms/codes/:${mobile}`
  })
}

/* 获取个人信息 */
export function getCurrentUser() {
  // let token = store.state.userInfo.token
  return request({
    method: 'GET',
    url: '/v1_0/user',
    /* 在 axios的请求拦截器中处理 token
    headers: {
      Authorization: `Bearer ${token}`
    } */
  })
}


// 获取自己信息
export function getUserProfile() {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/* 获取用户频道列表 */
export function getUserChannels() {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

// 关注用户
export const addFollow = userId => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}

// 取消关注用户
export const deleteFollow = userId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${userId}`
  })
}

// 获取用户自己信息
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
  })
}

// 更新用户信息
export const updateUserProfile = data => {
  return request({
    method: "PATCH",
    url: "/v1_0/user/profile",
    data
  })
}

// 修改用户头像
export const updateUserPhoto = data => {
  return request({
    method: "PATCH",
    url: '/v1_0/user/photo',
    data
  })
}